# coding: utf-8
from zUtils.mongodb import mongodb_system_js

mongodb_system_js.getNextSequence = """
function (name) {
    if (!db.CounterSequence.findOne({_id: name})) {
        db.CounterSequence.insertOne({_id: name, seq: 0})
    }
    var ret = db.CounterSequence.findAndModify(
        {
            query: {_id: name},
            update: {$inc: {seq: 1}},
            new: true
        }
    );

    return ret.seq;
}
"""
